package net.wexoo.onlinedivelog.dal.person;

import javax.persistence.Query;

import net.wexoo.onlinedivelog.dal.AbstractDAO;
import net.wexoo.onlinedivelog.entity.person.PersonBean;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PersonDAO extends AbstractDAO<PersonBean> implements IPersonDAO {

  public PersonDAO() {
    setClazz(PersonBean.class);
  }

  @Override
  public PersonBean login(String login, String password) {
    Query q = em.createQuery("from " + getBeanClassName() + " p where login like :login and password like :password");
    q.setParameter("login", login);
    q.setParameter("password", password);
    try {
      return (PersonBean) q.getSingleResult();
    } catch (Exception e) {
      Logger.getLogger(getClass()).debug("error on login: " + e);
      return null;
    }
  }
}